//state的getter计算属性的对象
export default {
  totalCount(state){
    return state.cartFoods.reduce((preTotal,food)=>{
      return preTotal + food.count
    },0)
  },
  totalPrice(state){
    // reduce计算数组元素相加后的总和
    return state.cartFoods.reduce((preTotal,food)=>{
      return preTotal + food.count * food.price
    },0)
  },
  positiveSize (state) {
    if (Array.isArray(state.ratings)) {
      return state.ratings.reduce((preTotal, rating) => preTotal + (rating.rateType === 0 ? 1 : 0), 0)

    }
  }
}
